﻿using AutoMapper;
using ManagementApi.Models;
using ManagementApi.Models.Logs;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Modules.SMS;

namespace ManagementApi.Controllers.SystemManage.Logs
{

    [Route("/api/v1/sysuser/smssendlog")]
    [ApiController]
    [Authorize(Roles = "SysUser")]
    public class SmsSendLogController : ControllerBase
    {
        private readonly SmsSendLogService smsSendLogService;
        private readonly IMapper mapper;
        public SmsSendLogController(SmsSendLogService smsSendLogService, IMapper mapper)
        {
            this.smsSendLogService = smsSendLogService;
            this.mapper = mapper;
        }

        /// <summary>
        /// 获取短信发送记录列表(分页)
        /// </summary>
        /// <param name="query">查询条件</param>
        /// <param name="pageNum">页码</param>
        /// <param name="pageSize">每页数量</param>
        /// <returns></returns>
        [HttpGet("page")]
        public ApiResult<PageDto<SmsSendLogDto>> GetSendLogs([FromQuery] SmsPageQuery query, int pageIndex = 1, int pageSize = 20)
        {
            var data = smsSendLogService.GetSendLogs(query, pageIndex, pageSize);
            var dtos = data.AsPageDto(source => { return source.AsDto(); });
            return ApiResult<PageDto<SmsSendLogDto>>.Success(dtos);
        }
    }
}
